package com.idp.biz.bpcomments.service.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.common.model.PageModel;
import com.common.utils.ResourceUtil;
import com.idp.biz.bpcomments.service.BpCommentsService;
import com.idp.biz.bpcomments.dao.BpCommentsDao;
import com.idp.biz.bpcomments.entity.BpComments;

/**
 * 点赞评论service实现类
 * 
 * @author Stone 2019-07-29
 *
 */
@Service("bpCommentsService")
public class BpCommentsServiceImpl implements BpCommentsService {

	@Autowired
	private BpCommentsDao bpCommentsDao;
	
	@Override
	public PageModel<BpComments> findByPage(BpComments bpComments, PageModel<BpComments> page) {
		PageHelper.offsetPage(page.getStart(), page.getLength());
		page.initData(bpCommentsDao.findByPage(bpComments));
		return page;
	}
	
	@Override
	public List<BpComments> findBySearch(BpComments bpComments) {
		return bpCommentsDao.find(bpComments);
	}
	
	@Override
	public BpComments getById(String id) {
		return bpCommentsDao.getById(id);
	}

	@Override
	public void add(BpComments bpComments) {
		bpComments.setId(ResourceUtil.getUUID());
		bpCommentsDao.add(bpComments);
	}
	
	@Override
	public void update(BpComments bpComments) {
//		bpCommentsDao.update(bpComments);
		bpCommentsDao.updateNotNull(bpComments);
	}

	@Override
	public void delete(String ids) {
		List<String> idList = Arrays.asList(ids.split(","));
		bpCommentsDao.batchDelete(idList);
	}
 	
}